(* Maximum number is : 6 * 9^5 = 354294 *)

fun Fifth_Power(a) = 
  let 
    val x = a * a;
  in
    x * x * a
  end;

fun cal(k, sum) = 
  if k = 0 then sum
  else cal(k div 10, sum + Fifth_Power(k mod 10));
  
fun ok(k) = 
  if cal(k, 0) = k then true
  else false;
  
fun Output(n, sum) = 
  if n > 354294 then sum
  else
    if ok(n) then  Output(n+1, sum+n)
	else Output(n+1, sum);
	
Output (2, 0);